import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oktoast/oktoast.dart';

/// 暂时封装toast
/// 具体使用根据实际情况来决定
///
class Toast {
  static const _defaultDuration = Duration(
    milliseconds: 2300,
  );

  static const _defaultToastPosition = ToastPosition.bottom;

  static const _defaultTextPadding = EdgeInsets.symmetric(horizontal: 5);

  static show(
    String msg, {
    Duration duration = _defaultDuration,
    ToastPosition position = _defaultToastPosition,
    EdgeInsetsGeometry textPadding = _defaultTextPadding,
  }) {
//每次显示toast先清除toast的堆栈
    clear();
    showToast(msg);
  }

  static void loading(String msg, {VoidCallback? onDismiss}) {
    Widget widget = Container(
        decoration: BoxDecoration(
          color: Colors.black.withOpacity(0.7),
          borderRadius: BorderRadius.circular(
            8.w,
          ),
        ),
        padding: EdgeInsets.symmetric(
          vertical: ScreenUtil().setWidth(28),
          horizontal: ScreenUtil().setWidth(36),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            SizedBox(
              width: ScreenUtil().setWidth(46),
              height: ScreenUtil().setWidth(46),
              child: const CircularProgressIndicator(
                backgroundColor: Colors.white,
                valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
                strokeWidth: 2.0,
              ),
            ),
            SizedBox(
              height: 12.h,
            ),
            Text(
              msg,
              style: const TextStyle(
                fontSize: 14.0,
                color: Colors.white,
              ),
            )
          ],
        ));
    dismissAllToast();
    showToastWidget(widget,
        position: ToastPosition.center,
        duration: const Duration(minutes: 1),
        onDismiss: onDismiss?.call,
        dismissOtherToast: true);
  }

// static void showBubble({required String message,Offset offset = const Offset(1, 1)}){
//   final Widget _child = Padding(
//     padding: EdgeInsets.only(left: offset.dx),
//     // padding: EdgeInsets.only(left: 51),
//     child: BubbleView(message: message,callback: (height) => offset.translate(0, - height),),
//   );
//   dismissAllToast();
//   showToastWidget(_child,duration: Duration(seconds: 2),position: ToastPosition(align: Alignment.centerLeft,offset: offset.dy - 15));
//   // showToastWidget(_child,duration: Duration(seconds: 1),position: ToastPosition(align: Alignment.centerLeft,offset: 365));
//   // showToastWidget(_child,duration: Duration(seconds: 1),position: ToastPosition(align: Alignment.centerLeft,offset: 200),dismissOtherToast: false);
//   // showToastWidget(_child,duration: Duration(seconds: 1),position: ToastPosition(align: Alignment.centerLeft,offset: 300),dismissOtherToast: false);
// }

// 清除toast的所有堆栈
  static void clear() => dismissAllToast();
}
